package com.demo.web.generator.params.${lowerDomainObjectName};

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.demo.web.generator.entity.${domainObjectName};
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.sql.Wrapper;
import java.util.List;

/**
 * @author fengz
 * @version v1
 * @className Criterion
 * @description TODO
 * @site glp.hcdlearning.com
 * @company 合得软件（上海）有限公司
 * @create ${date} ${time}
 */
@Data
@Builder
@ToString
@EqualsAndHashCode
public class Criterion {


    <#list fields as f>
    // ++++++++    ${f.name} 属性    ++++++++//
    String ${f.name}Eq;
    String ${f.name}Like;
    String ${f.name}Lt;
    String ${f.name}Gt;
    String ${f.name}InSql;
    List<String> ${f.name}In;
    List<String> ${f.name}Power;
    List<String> ${f.name}Ext;

    public void set${f.upperName}In(String ${f.name}In){
        this.${f.name}In = CollUtil.newArrayList(${f.name}In);
    }
    public void set${f.upperName}Power(String ${f.name}Power){
        this.${f.name}Power = CollUtil.newArrayList(${f.name}Power);
    }
    public void set${f.upperName}Ext(String ${f.name}Ext){
        this.${f.name}Ext = CollUtil.newArrayList(${f.name}Ext);
    }
    private AbstractLambdaWrapper<${domainObjectName},?> ${f.name}Build(AbstractLambdaWrapper<${domainObjectName},?> wrapper){
        wrapper
                .eq(StrUtil.isNotBlank(this.get${f.upperName}Eq()),${domainObjectName}::get${f.upperName},this.get${f.upperName}Eq())
                .like(StrUtil.isNotBlank(this.get${f.upperName}Like()),${domainObjectName}::get${f.upperName},this.get${f.upperName}Like())
                .lt(this.get${f.upperName}Lt()!=null,${domainObjectName}::get${f.upperName},this.get${f.upperName}Lt())
                .gt(this.get${f.upperName}Gt()!=null,${domainObjectName}::get${f.upperName},this.get${f.upperName}Gt())
                .inSql(StrUtil.isNotBlank(this.get${f.upperName}InSql()),${domainObjectName}::get${f.upperName},this.get${f.upperName}InSql())
                .in(CollUtil.isNotEmpty(this.get${f.upperName}In()),${domainObjectName}::get${f.upperName},this.get${f.upperName}In())
        ;
        if(CollUtil.isNotEmpty(this.get${f.upperName}Power())) {
            this.get${f.upperName}Power().forEach(p -> {
                wrapper.apply(" c_delete & {0} = {0}", p);
            });
        }
        if(CollUtil.isNotEmpty(this.get${f.upperName}Ext())){
            this.get${f.upperName}Ext().forEach( p ->{
                wrapper.apply(p);
            });
        }
        return wrapper;
    }
    // ++++++++    ${f.name} 属性    ++++++++//
    </#list>
    private AbstractLambdaWrapper<${domainObjectName},?> build(AbstractLambdaWrapper<${domainObjectName},?> wrapper){
        <#list fields as f>
        wrapper = ${f.name}Build(wrapper);
        </#list>
        return wrapper;
    }

    public AbstractLambdaWrapper<${domainObjectName},?> buildQuery(){
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = Wrappers.<${domainObjectName}>lambdaQuery();
        return build(wrapper);
    }
    public AbstractLambdaWrapper<${domainObjectName},?> buildUpdate(){
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = Wrappers.<${domainObjectName}>lambdaUpdate();
        return build(wrapper);
    }
}
